﻿using System.Collections.Generic;

public class ChessShuai : BaseChess
{
    private Pos[] directions = new Pos[4] { new Pos(0, -1), new Pos(0, 1), new Pos(-1, 0), new Pos(1, 0) };
    public ChessShuai(int camp, int team) : base(camp, team)
    {

    }
    public override void AddSomePosIntoList(BaseChessBoard chessBoard, List<Pos> tempPosList)
    {
        if (!(chessBoard is StandardChessBoard))
        {
            return;
        }
        BaseGrid grid = chessBoard.GetGridByChess(this);
        if (grid != null)
        {
            Pos chessPos = grid.GetPos();
            Pos endPos;
            int i = 0;
            for (i = 0; i < directions.Length; i++)
            {
                endPos = chessPos.AddResult(directions[i]);
                if (chessBoard.SpaceIsGridAndNotExistChess(endPos) || chessBoard.SpaceIsGridAndExistOtherTeamChess(endPos, GetTeam()))
                {
                    BaseGrid endGrid = chessBoard.GetGridByPos(endPos);
                    StandardGrid sEndGrid = endGrid as StandardGrid;
                    if (sEndGrid != null && sEndGrid.GetIsPalace() == true && sEndGrid.GetCamp() == GetCamp())
                    {
                        tempPosList.Add(endPos);
                    }
                }
            }
            i = 1;
            for (; ; i++)
            {
                endPos = chessPos.AddResult(((StandardChessBoard)chessBoard).GetForwardDirectionByCamp(GetCamp()).MulResult(i));
                if (!chessBoard.SpaceIsGridAndNotExistChess(endPos))
                {
                    break;
                }
            }
            endPos = chessPos.AddResult(((StandardChessBoard)chessBoard).GetForwardDirectionByCamp(GetCamp()).MulResult(i));
            if (chessBoard.SpaceIsGridAndExistOtherTeamChess(endPos, GetTeam()))
            {
                BaseChess enemyShuaiChess = chessBoard.GetChessByGrid(chessBoard.GetGridByPos(endPos));
                if (enemyShuaiChess.GetTeam() != GetTeam() && enemyShuaiChess.GetScore(chessBoard).infCount > 0)
                {
                    tempPosList.Add(endPos);
                }
            }
        }
    }
    public override Score GetScore(BaseChessBoard baseChessBoard)
    {
        return new Score(0, 1);
    }
}